//
//  SinaTabBar.m
//  MySinaWeiboProjectForOC
//
//  Created by apple on 2016/11/12.
//  Copyright © 2016年 WangChen. All rights reserved.
//

#import "SinaTabBar.h"

@interface SinaTabBar ()

@property (nonatomic,strong) UIButton *btn;

@end

@implementation SinaTabBar

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupTabBar];
    }
    return self;
}


#pragma mark
#pragma mark - 布置自定义tabBar
-(void)setupTabBar{
    
    [self addSubview:self.btn];
    
    
}


#pragma mark
#pragma mark - 重写layout
-(void)layoutSubviews{
    
    [super layoutSubviews];
    
    CGFloat w = [UIScreen mainScreen].bounds.size.width * 0.2;
    CGFloat h = self.bounds.size.height;
    
    NSInteger index = 0;
    
    for (UIView *subView in self.subviews) {
        if([subView isKindOfClass:NSClassFromString(@"UITabBarButton")]){
            
            subView.frame = CGRectMake(index * w, 0, w, h);
            
            index += (index == 1?2 : 1);
        }
    }
    
    self.btn.bounds = CGRectMake(0, 0, w, h);
    self.btn.center = CGPointMake(self.center.x, h / 2.0);
    
}




#pragma mark
#pragma mark - 懒加载按钮
-(UIButton *)btn{
    
    if(_btn == nil){
        _btn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [_btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [_btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        
        [_btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [_btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        
        [_btn sizeToFit];
        
        [_btn addTarget:self action:@selector(composeButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _btn;
}



#pragma mark
#pragma mark - 撰写按钮监听
-(void)composeButtonDidClick{
    
    self.composeBtnDidClick();
    
}


@end
